package ioperation;

import book.Book;
import book.BookList;
import exception.BorrowException;

import java.util.Scanner;

public class BorrowOperation implements IOperation {
    @Override
    public void work(BookList bookList) throws BorrowException{
        System.out.println("请输入想借阅的书名：");
        Scanner sc = new Scanner(System.in);
        String name = sc.nextLine();
        for (int i = 0; i < bookList.getUsedsize(); i++) {
            Book book = bookList.getBook(i);
            if(book.getName().equals(name)){
               if(!book.isIsborrow()){
                   book.setIsborrow(true);
                   System.out.println("借阅成功！！");
                   return;
               }else {
                   throw new BorrowException("该图书已经被借出....");
               }
            }
        }
        throw new BorrowException("该图书不存在.....");
    }
}
